package com.fzk.blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzk.blog.bean.Comment;
import com.fzk.blog.bean.vo.CommentInfo;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.math.BigInteger;
import java.util.List;

/**
 * @author fzk
 * @date 2021-08-15 15:54
 */
public interface CommentMapper extends BaseMapper<Comment> {
    @Select("SELECT id,user_id userId,blog_id blogId,content," +
            "   publish_date publishDate,create_time createTime" +
            "   FROM tbl_comment" +
            "   WHERE id=#{id} AND flag=0 ")
    CommentInfo getCommentInfoById(BigInteger id);

    @SelectProvider(CommentSqlProvider.class)//动态SQL
    List<CommentInfo> getCommentInfoListPage(Integer blogId, Integer userId, Integer index, Integer pageSize);

    @SelectProvider(CommentSqlProvider.class)//动态SQL:与上一个几乎一致，区别在于没有分页，且返回int
    int getCommentInfoTotal(Integer blogId, Integer userId, Integer index, Integer pageSize);

    @Select("SELECT COUNT(*) FROM tbl_comment WHERE user_id=#{userId} AND flag=0 ")
    int getNumberByUserId(int userId);

}
